package railRoad.web.slaves;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import railRoad.Route;
import railRoad.Schedule;
import railRoad.web.slaves.interfaces.ISlaveServlet;
import railRoad.worker.FactoryRW;

public class RouteRemoveServlet implements ISlaveServlet {

	public void work(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		Map<?, ?> parameterMap = req.getParameterMap();

		if (parameterMap.containsKey("id_route")) {

			int routeId = Integer.valueOf(req.getParameterValues("id_route")[0]);

			Schedule schedule = Schedule.getInstance();

			Route route = schedule.getRouteById(routeId);

			FactoryRW.delete(route);

			schedule.removeRoute(route);
		}// if parameterMap
		resp.sendRedirect("/pages/create_order.do");
	}// work

}// RouteRemoveServlet
